package main

import (
	"go-init/api/common"
	"go-init/api/user"
	"go-init/dao"
	_ "go-init/docs"
	"go-init/lib/config"
	"go-init/lib/ctx"

	"github.com/didi/gendry/scanner"

	ginSwagger "github.com/swaggo/gin-swagger"

	"github.com/gin-contrib/pprof"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"

	swaggerFiles "github.com/swaggo/files"
)

func setRouter() *gin.Engine {
	r := gin.Default()
	r.Static("/static", "static")
	r.Use(ctx.Cors())
	g := r.Group("/api")
	store := cookie.NewStore([]byte("secret"))
	//store.Options(sessions.Options{SameSite: 4, Secure: true})
	g.Use(sessions.Sessions("mysession", store))
	//sessionignorelist := []string{}
	//g.Use(ctx.Prepare(sessionignorelist))
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	user.SetRouter(g)
	common.SetRouter(g)
	//if err := agent.Listen(agent.Options{}); err != nil {
	//	log.Fatal(err)
	//}
	pprof.Register(r, "api/pprof")
	return r
}

// @title baidaplm
// @version 1.0
// @description This is a sample server Petstore server.

// @contact.name hyperq
// @contact.url http://www.github.com/hyperq
// @contact.email hyperq1g@gmail.com

// @basePath /
// @host localhost:8080

func main() {
	config.Init()
	dao.Init()
	scanner.SetTagName("json")
	r := setRouter()
	err := r.Run(":8080")
	if err != nil {
		panic(err)
	}
}
